<!--学生通讯录（整合：化缘）-->
<?php include('header.php') ?>


<div id="mainbody"  >
          <div class="col-lg-9" id="charge">
          <table class="table table-bordered" id="work-table">
          <tr id="table-nav">
                 <td> 学号</td>
          		 <td> 姓名</td>
	             <td>性别</td>
          		 <td> 学院</td>
                 <td>专业</td>
          		  <td>手机</td>
          	</tr>
<?php

//取出学生信息
function table(){
// 	$sql="select * from $tabname";
	$sql = " drop table if exists tmp_student_info";
	mysql_query($sql);
	$sql1 = "create table tmp_student_info (studentid bigint(11),studentname varchar(20),
		sex varchar(3),college varchar(35),major varchar(35),phone varchar(25)) default charset = utf8";
	mysql_query($sql1);

	$sql="insert into tmp_student_info SELECT studentworkinlibrary.studentid,studentname,sex,college,major,phone FROM allstudent join studentworkinlibrary on studentworkinlibrary.studentid=allstudent.studentid and stillwork='yes'";
	mysql_query($sql);
	$sql2="select * from tmp_student_info";
	$result=mysql_query($sql2);
	if ($result==null){
		echo "结果为空!";
	}
	
	$url="stuinfo.php";
	//每页显示的记录条数
	$num=10;
	//sql结果集记录总条数
	$total=mysql_num_rows($result);
	//ceil()函数,向上取整. 总页码
	$pagenum=ceil($total/$num);
	//确定当前页码.
	$cpage=isset($_GET["page"])?$_GET["page"]:1;
	//limit偏移量
	$offset=($cpage-1)*$num;
	$sql="select * from tmp_student_info limit {$offset},{$num}";
	$result=mysql_query($sql);
	//当前页起始记录
	$start=$offset+1;
	//当前页最后一条记录
	$end=($cpage==$pagenum)?$total:($cpage*$num);
	//上一页
	$prev=($cpage==1)?0:($cpage-1);
	//下一页
	$next=($cpage==$pagenum)?0:($cpage+1);
		
	$rows=mysql_num_rows($result);
	$cols=mysql_num_fields($result);
	//输出值
	while($row=mysql_fetch_array($result)){
		echo '<tr >';
		echo '<td>'.$row["studentid"].'</td>';
		echo  '<td>'.$row["studentname"] .'</td>';
		echo  '<td>'.$row["sex"] .'</td>';
		echo  '<td>'.$row["college"] .'</td>';
		echo  '<td>'.$row["major"] .'</td>';
		echo  '<td>'.$row["phone"] .'</td>';
		echo '</tr>';
	}
	echo '<tr align="center"><td colspan="'.$cols.'">';
	echo "共：{$total}条记录，当前显示：{$start}-{$end}，当前页面：{$cpage}/{$pagenum}";
	//判断"首页"按钮是否可用.
	if($cpage==1)
		echo "&nbsp;&nbsp;首页&nbsp;&nbsp;";
	else
		echo "&nbsp;&nbsp;<a href='{$url}?page=1'>首页</a>&nbsp;&nbsp;";
	//判断上一页是否可用
	if($prev)
		echo "&nbsp;&nbsp;<a href='{$url}?page={$prev}'>上一页</a>&nbsp;&nbsp;";
	else
		echo "&nbsp;&nbsp;上一页&nbsp;&nbsp;";
	//判断下一页是否可用
	if($next)
		echo "&nbsp;&nbsp;<a href='{$url}?page={$next}'>下一页</a>&nbsp;&nbsp;";
	else
		echo "&nbsp;&nbsp;下一页&nbsp;&nbsp;";
	//判断"尾页"按钮是否可用
	if($cpage==$pagenum)
		echo "&nbsp;&nbsp;尾页&nbsp;&nbsp;";
	else
		echo "&nbsp;&nbsp;<a href='{$url}?page={$pagenum}'>尾页</a>&nbsp;&nbsp;";
	echo '</tr></td>';
	echo '</table>';
	mysql_free_result($result);
	mysql_close();
}
table();
?> 	
          </table>
<?php include('foot.php') ?>